<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>横向图片滚动展示</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            /* background: linear-gradient(135deg, red 0%, green 100%); */
            color: #333;
            line-height: 1.6;
            padding: 20px;
            min-height: 100vh;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
            padding: 30px;
        }
        
        header {
            text-align: center;
            margin-bottom: 30px;
        }
        
        h1 {
            color: #2c3e50;
            margin-bottom: 10px;
        }
        
        .subtitle {
            color: #7f8c8d;
            font-size: 1.1rem;
        }
        
        .gallery-container {
            position: relative;
            margin: 30px 0;
        }
        
        .gallery {
            display: flex;
            overflow-x: auto;
            padding: 20px 0;
            scroll-behavior: smooth;
            gap: 15px;
            scrollbar-width: thin;
            scrollbar-color: #3498db #f1f1f1;
        }
        
        /* 自定义滚动条样式 */
        .gallery::-webkit-scrollbar {
            height: 10px;
        }
        
        .gallery::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 10px;
        }
        
        .gallery::-webkit-scrollbar-thumb {
            background: #3498db;
            border-radius: 10px;
        }
        
        .gallery::-webkit-scrollbar-thumb:hover {
            background: #2980b9;
        }
        
        .image-card {
            flex: 0 0 auto;
            width: 300px;
            height: 200px;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .image-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        }
        
        .image-card img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        .controls {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-top: 20px;
        }
        
        button {
            background: #3498db;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s;
        }
        
        button:hover {
            background: #2980b9;
        }
        
        button:disabled {
            background: #bdc3c7;
            cursor: not-allowed;
        }
        
        .info {
            background: #e8f4fc;
            padding: 15px;
            border-radius: 8px;
            margin-top: 20px;
            border-left: 4px solid #3498db;
        }
        
        @media (max-width: 768px) {
            .container {
                padding: 15px;
            }
            
            .image-card {
                width: 250px;
                height: 180px;
            }
        }
        
        @media (max-width: 480px) {
            .image-card {
                width: 200px;
                height: 150px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>横向图片滚动展示</h1>
            <p class="subtitle">使用横向滚动条浏览所有图片</p>
        </header>
        
        <div class="gallery-container">
            <div class="gallery" id="gallery">
                <!-- 图片将通过JavaScript动态添加 -->
            </div>
        </div>
        
        <div class="controls">
            <button id="prevBtn">上一张</button>
            <button id="nextBtn">下一张</button>
            <button id="scrollToStart">滚动到开头</button>
            <button id="scrollToEnd">滚动到末尾</button>
        </div>
        
        <div class="info">
            <p><strong>提示：</strong> 您可以使用鼠标滚轮、拖动滚动条或点击控制按钮来浏览图片。当图片超出容器宽度时，会自动显示横向滚动条。</p>
        </div>
    </div>

    <script>
        // 图片数据 - 使用Picsum提供的随机图片
        const images = [
            { id: 1, url: 'https://picsum.photos/300/200?random=1', title: '风景图片 1' },
            { id: 2, url: 'https://picsum.photos/300/200?random=2', title: '风景图片 2' },
            { id: 3, url: 'https://picsum.photos/300/200?random=3', title: '城市风光 1' },
            { id: 4, url: 'https://picsum.photos/300/200?random=4', title: '城市风光 2' },
            { id: 5, url: 'https://picsum.photos/300/200?random=5', title: '自然景观 1' },
            { id: 6, url: 'https://picsum.photos/300/200?random=6', title: '自然景观 2' },
            { id: 7, url: 'https://picsum.photos/300/200?random=7', title: '建筑风格 1' },
            { id: 8, url: 'https://picsum.photos/300/200?random=8', title: '建筑风格 2' },
            { id: 9, url: 'https://picsum.photos/300/200?random=9', title: '抽象艺术 1' },
            { id: 10, url: 'https://picsum.photos/300/200?random=10', title: '抽象艺术 2' }
        ];
        
        const gallery = document.getElementById('gallery');
        const prevBtn = document.getElementById('prevBtn');
        const nextBtn = document.getElementById('nextBtn');
        const scrollToStartBtn = document.getElementById('scrollToStart');
        const scrollToEndBtn = document.getElementById('scrollToEnd');
        
        // 动态添加图片到画廊
        images.forEach(image => {
            const imageCard = document.createElement('div');
            imageCard.className = 'image-card';
            
            const img = document.createElement('img');
            img.src = image.url;
            img.alt = image.title;
            
            imageCard.appendChild(img);
            gallery.appendChild(imageCard);
        });
        
        // 上一张按钮事件
        prevBtn.addEventListener('click', () => {
            gallery.scrollBy({
                left: -320, // 图片宽度 + 间距
                behavior: 'smooth'
            });
        });
        
        // 下一张按钮事件
        nextBtn.addEventListener('click', () => {
            gallery.scrollBy({
                left: 320, // 图片宽度 + 间距
                behavior: 'smooth'
            });
        });
        
        // 滚动到开头
        scrollToStartBtn.addEventListener('click', () => {
            gallery.scrollTo({
                left: 0,
                behavior: 'smooth'
            });
        });
        
        // 滚动到末尾
        scrollToEndBtn.addEventListener('click', () => {
            gallery.scrollTo({
                left: gallery.scrollWidth,
                behavior: 'smooth'
            });
        });
        
        // 更新按钮状态
        function updateButtonStates() {
            prevBtn.disabled = gallery.scrollLeft <= 0;
            nextBtn.disabled = gallery.scrollLeft + gallery.clientWidth >= gallery.scrollWidth;
        }
        
        // 监听滚动事件
        gallery.addEventListener('scroll', updateButtonStates);
        
        // 初始更新按钮状态
        updateButtonStates();
    </script>
</body>
</html>